home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / server / startclients.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  2.0 KB  |  109 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dostags.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10.  
  11. #include "/include/server.h"
  12.  
  13.  
  14. extern struct List ClientsList;
  15. extern UWORD TotalClients;
  16.  
  17. #define MAXCLIENTS 100
  18.  
  19. struct TagItem systags[4] = { SYS_Asynch, TRUE, SYS_Input, NULL, SYS_Output, NULL, TAG_END };
  20.  
  21.  
  22. BOOL StartClient( struct ClientNode *node )
  23. {
  24. BPTR lock;
  25. char path[128], *cp;
  26.  
  27. if ( lock = Lock( node->cn_ClientName, ACCESS_READ ) )
  28.     {
  29.     UnLock( lock );
  30.     strcpy( path, node->cn_ClientName );
  31.  
  32.     cp = path + strlen( path ) -1;
  33.     while( cp > path && *cp != '/' && *cp != ':' )
  34.         cp--;
  35.     if ( cp > path )
  36.         {
  37.         *cp = 0;
  38.         cp++;
  39.         }
  40.     lock = Lock( path, ACCESS_READ );
  41.     CurrentDir( lock );
  42.     if ( SystemTagList( cp, systags ) != -1 )
  43.         {
  44.         return TRUE;
  45.         }
  46.     }
  47. return FALSE;
  48. }
  49.  
  50.  
  51. void AddClient( char *newname )
  52. {
  53. struct ClientNode *node;
  54.  
  55. if ( node = AllocVec( sizeof(struct ClientNode), MEMF_ANY | MEMF_CLEAR ) )
  56.     {
  57.     strcpy( node->cn_ClientName, newname );
  58.     node->cn_Node.ln_Name = FilePart( node->cn_ClientName );
  59.     AddTail( &ClientsList, (struct Node *)node );
  60.     TotalClients++;
  61.     }
  62. }
  63.  
  64.  
  65. void GetClientNames( char *listname )
  66. {
  67. BPTR handle;
  68. struct FileInfoBlock fib;
  69. register ULONG size;
  70. register char *ptr, *current;
  71. register char newclient[CLIENTNAME_MAXLENGTH];
  72. register UBYTE n;
  73.  
  74. if ( handle = Open( listname, MODE_OLDFILE ) )
  75.     {
  76.     if ( ExamineFH( handle, &fib ) )
  77.         {
  78.         size = fib.fib_Size;
  79.         if ( ptr = AllocVec( size, MEMF_ANY ) )
  80.             {
  81.             Read( handle, ptr, size );
  82.  
  83.             current = ptr;
  84.             while( current < ( ptr + size ) )
  85.                 {
  86.                 n = 0;
  87.                 while( *current != '\n' && current < ( ptr + size ) )
  88.                     newclient[n++] = *current++;
  89.                 newclient[n] = 0;
  90.                 current++;
  91.                 if ( newclient[0] )
  92.                     AddClient( newclient );
  93.                 }
  94.             FreeVec( ptr );
  95.             }
  96.         }
  97.     Close( handle );
  98.     }
  99. }
  100.  
  101.  
  102. void DropClientNames( void )
  103. {
  104. struct ClientNode *node;
  105.  
  106. while ( node = (struct ClientNode *)RemHead( &ClientsList ) )
  107.     FreeVec( node );
  108. }
  109.